/**
 * 初始化开单详情对话框
 */
var InitialOrderInfoDlg = {
    initialOrderInfoData : {}
};

/**
 * 清除数据
 */
InitialOrderInfoDlg.clearData = function() {
    this.initialOrderInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
InitialOrderInfoDlg.set = function(key, val) {
    this.initialOrderInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
InitialOrderInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
InitialOrderInfoDlg.close = function() {
    parent.layer.close(window.parent.InitialOrder.layerIndex);
}

/**
 * 收集数据
 */
InitialOrderInfoDlg.collectData = function() {
    this
    .set('id')
    .set('sendDeptName')
    .set('goodsName')
    .set('goodsPiece')
    .set('goodsWeight')
    .set('goodsVolume')
    .set('payment')
    .set('collection')
    .set('still')
    .set('backAmount')
    .set('settlement')
    .set('consignee')
    .set('receivingPhone')
    .set('receivingAddress')
    .set('mode')
    .set('notice')
    .set('receipt')
    .set('createtime')
    .set('userId')
    .set('orderNum')
    .set('isNormal')
    .set('isTransfer')
    .set('batchNo')
    .set('dotId')
    .set('provinceCode')
    .set('cityCode')
    ;
}

/**
 * 提交添加
 */
InitialOrderInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/initialOrder/add", function(data){
        Feng.success("添加成功!");
        window.parent.InitialOrder.table.refresh();
        InitialOrderInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.initialOrderInfoData);
    ajax.start();
}

InitialOrderInfoDlg.closeDialog=function(){
    window.parent.InitialOrder.table.refresh();
    InitialOrderInfoDlg.close();
}

InitialOrderInfoDlg.downloadFailureList=function(){
    location.href=Feng.ctxPath + "/initialOrder/export?batch_no="+$('#batch_no').val();

}
/**
 * 提交修改
 */
InitialOrderInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/initialOrder/update", function(data){
        Feng.success("修改成功!");
        window.parent.InitialOrder.table.refresh();
        InitialOrderInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.initialOrderInfoData);
    ajax.start();
}

$(function() {
    // 初始化头像上传
    var avatarUp = new $WebUploadExecl("avatar");
    avatarUp.setUploadBarId("progressBar");
    avatarUp.init();

    $("#transfer_name").bsSuggest('init', {
        /*url: "/rest/sys/getuserlist?keyword=",
        searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{dotName: "网点名称"},
        effectiveFields: ["id", "dotName"],
        clearable: true,
        url: Feng.ctxPath + "/tOrder/searchDotList",
        idField: "id",
        keyField: "dotName"
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
        a=result.value;
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log('onSetSelectValue: ', keyword, e);
        $('#transferId').val(keyword.id);
    }).on('onUnsetSelectValue', function () {
        console.log('onUnsetSelectValue');
        $('#transferId').val('');
    });

    var a;
    $("#driver_name").bsSuggest('init', {
        /*url: "/rest/sys/getuserlist?keyword=",
        searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{driver_name: "司机"},
        effectiveFields: ["id", "driver_name"],
        clearable: true,
        url: Feng.ctxPath + "/tOrder/searchList",
        idField: "id",
        keyField: "driver_name"
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
        a=result.value;
    }).on('onSetSelectValue', function (e, keyword, data) {
        // console.log('onSetSelectValue: ', keyword, e);
        // for(var i=0;i<a.length;i++){
        //     console.log('onSetSelectValue: ',a[i].id);
            $('#driverId').val(keyword.id);
            // if(a[i].id==keyword.id){
            //     $('#card').val(a[i].driver_card);
            //     $('#carNo').val(a[i].car_no);
            //
            // }
        // }
    }).on('onUnsetSelectValue', function () {
        console.log('onUnsetSelectValue');
        $('#driverId').val('');
    });

});



